package peer.p2pnet.message;

import java.net.DatagramPacket;

import peer.Message;
import peer.tools.ByteIntSwitch;
import peer.tools.ByteShortSwitch;
import peer.tools.Mdb;

public class CleanMessage extends Message{
	public short sType=peer.tools.MessageType.sType_CleanMessage1;
	Mdb mdb;
	int sourceSessionId;
	byte[] dpData=new byte[24];
	public CleanMessage (Mdb mdb,int sourceSessionId){
		this.mdb=mdb;
		this.sourceSessionId=sourceSessionId;
		ByteShortSwitch.toByteArray(ver, dpData, 0);  //add: ver
		ByteShortSwitch.toByteArray(sType, dpData, 2);  //add: service type
		System.arraycopy(mdb.md, 0, dpData, 4, 16);
		ByteIntSwitch.toByteArray(sourceSessionId, dpData, 20);  //add: sessionId
		dp=new DatagramPacket(dpData,dpData.length);
		@SuppressWarnings("unused")
		int ss=ByteShortSwitch.toShort(dpData, 2);
	}
	
	public CleanMessage(DatagramPacket dp){
		this.dp=dp;
		dpData=dp.getData();
		ver=ByteShortSwitch.toShort(dpData, 0);
		sType=ByteShortSwitch.toShort(dpData, 2);
		byte[] md=new byte[16];
		mdb=new Mdb(md);
		System.arraycopy(dpData, 4, md, 0, 16);
		sourceSessionId=ByteIntSwitch.toInt(dpData, 20);
	}
	
	public int getSourceSessionId(){
		return sourceSessionId;
	}
	
	public Mdb getMdb(){
		return mdb;
	}
	
}
